*************************************************
*   SET DATA AS SPATIAL AND GENERATE MATRICES   *
*                                               *
*  This code need only be run once; user should *
*     set file path using cd command to ensure  *
*        spatial matrices are saved in an       *
*       appropriate location for later use      *
*                                               *
*************************************************

*SET FILE PATH


use "Piracy Replication Data.dta", clear

cd "USER FILE PATH HERE"

sort id year_bin
xtset id year_bin, yearly

* NB:  x = longitude, y = latitude
spset id, coord(cent_long cent_lat) coordsys(latlong, kilometers)


* GENERATE MATRICES FOR LATER USE

spmatrix create idistance W250n if year == 2005 & to_use_panel == 1 & to_keep3 == 1, vtruncate(1/250) normalize(spectral)
spmatrix save W250n using W250n.stswm

spmatrix create idistance W500n if year == 2005 & to_use_panel == 1 & to_keep5 == 1, vtruncate(1/500) normalize(spectral)
spmatrix save W500n using W500n.stswm

spmatrix create idistance W1000n if year == 2005 & to_use_panel == 1 & to_keep5 == 1, vtruncate(1/1000) normalize(spectral)
spmatrix save W1000n using W1000n.stswm

spset, clear
